package com.lf.util;

import com.alibaba.fastjson.JSONObject;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
// 导入对应产品模块的 client
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
// 导入要请求接口对应的 request response 类
import com.tencentcloudapi.faceid.v20180301.FaceidClient;
import com.tencentcloudapi.faceid.v20180301.models.PhoneVerificationRequest;
import com.tencentcloudapi.faceid.v20180301.models.PhoneVerificationResponse;

public class DescribeZones
{
    public static boolean PhoneVerification(String name,String idCard,String phone,String SECRET_ID,String SECRET_KEY) {
        try{
            // 实例化一个认证对象，入参需要传入腾讯云账户 secretId，secretKey
            Credential cred = new Credential(SECRET_ID,SECRET_KEY);
            // 实例化要请求产品（以 CVM 为例）的 client 对象
//            CvmClient client = new CvmClient(cred, "ap-guangzhou");
            // 实例化一个请求对象
//            DescribeZonesRequest req = new DescribeZonesRequest();
            // 通过 client 对象调用想要访问的接口，需要传入请求对象
//            DescribeZonesResponse resp = client.DescribeZones(req);
            // 输出 JSON 格式的字符串回包
//            System.out.println(DescribeZonesRequest.toJsonString(resp));


            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("faceid.tencentcloudapi.com");

            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);

            FaceidClient client = new FaceidClient(cred, "ap-guangzhou", clientProfile);

            String params = "{\"IdCard\":\""+idCard+"\",\"Name\":\""+name+"\",\"Phone\":\""+phone+"\"}";
            PhoneVerificationRequest req = PhoneVerificationRequest.fromJsonString(params, PhoneVerificationRequest.class);

            PhoneVerificationResponse resp = client.PhoneVerification(req);

            String jsonstr = PhoneVerificationRequest.toJsonString(resp);
            System.out.println(jsonstr);
            JSONObject jsonObject = JSONObject.parseObject(jsonstr);
            if ("0".equals(jsonObject.getString("Result"))){
                return true;
            }
            return false;
        } catch (TencentCloudSDKException e) {
            System.out.println(e.toString());
        }
        return false;
    }
}